<?php
class ControllerUser_type { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newUsertype();
                break;
            
            case "list":
                $this->listUsertype();
                break;
            
            case "save":
                $this->saveUsertype();
                break;

            case "edit":
                $this->editUsertype();
                break;
            
            case "update":
                $this->updateUsertype();
                break;
            
            case "del":
                $this->deleteUsertype();
                break;
            
            case "combo":
                return $this->comboUsertype();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newUsertype(){
        include_once "vista/vista.user_type.php";
        form_user_type();
    }    
    

    function saveUsertype(){
        include_once "modelo/modelo.user_type.php";
        
        $u = new user_type();
        $u->set_ut_id($_REQUEST["ut_id"]); 
        $u->set_ut_desc($_REQUEST["ut_desc"]); 
        $u->set_ut_status($_REQUEST["ut_status"]); 

        
        if($u->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listUsertype($msj);
        
    }    
    
    function editUsertype(){
        include_once 'modelo/modelo.user_type.php';
        include_once 'vista/vista.user_type.php';
        
        $u = new user_type();
        $u->setut_id($_REQUEST["ut_id"]); 
        
        $u->getData();
        
        form_user_type($u);
        
    }    
    
    function deleteUsertype(){
        include_once 'modelo/modelo.user_type.php';
        
        $u = new user_type();
        $u->setut_id($_REQUEST["ut_id"]); 
        
        if($u->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listUsertype($msj);
    }

    
    function updateUsertype(){
        include_once 'modelo/modelo.user_type.php';
        
        $u = new user_type();
        $u->set_ut_id($_REQUEST["ut_id"]); 
        $u->set_ut_desc($_REQUEST["ut_desc"]); 
        $u->set_ut_status($_REQUEST["ut_status"]); 

        if($u->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listUsertype($msj);
    }

    
    function listUsertype($msj=false){
        include_once 'modelo/modelo.user_type.php';
        include_once 'vista/vista.user_type.php';
        
        $u = new user_type();

        $u->setut_id($_REQUEST["ut_id"]); 
        $u->getData();
        
        $dataTotal = $u->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $u->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_user_type($data, $msj, $dataTotal);

    }

}